package com.quasar.hpatient.dialog;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.quasar.hpatient.R;
import com.quasar.hpatient.bean.home_inspection.InspectionBean;

import java.util.ArrayList;
import java.util.List;

import lib.quasar.base.dialog.BaseDialog;
import lib.quasar.context.BaseApp;
import lib.quasar.recycler.BaseCommonAdapter;
import lib.quasar.recycler.holder.RecyclerHolder;
import lib.quasar.recycler.manager.CrashLinearLayoutManager;
import lib.quasar.util.SpannableUtil;

public class EventDialog extends BaseDialog {

    private ArrayList<InspectionBean.EventBean> mDatas = new ArrayList();
    private final BaseCommonAdapter<InspectionBean.EventBean> adapter = new BaseCommonAdapter<InspectionBean.EventBean>(mDatas, R.layout.layout_dialog_event_child) {
        @Override
        protected void onNext(RecyclerHolder holder, InspectionBean.EventBean model, int position) {

            SpannableUtil.append("不适症状：", BaseApp.getResource().getColor(R.color.color_bg_theme));
            SpannableUtil.append(model.getEvent_name(), BaseApp.getResource().getColor(R.color.color_black));
            holder.setText(R.id.dialog_event_menu1, SpannableUtil.build());

            SpannableUtil.append("持续时间：", BaseApp.getResource().getColor(R.color.color_bg_theme));
            if ("0".equals(model.getDuration_Length())) {
                SpannableUtil.append("5天以上", BaseApp.getResource().getColor(R.color.color_black));
            } else {
                SpannableUtil.append(model.getDuration_Length() + "天", BaseApp.getResource().getColor(R.color.color_black));
            }
            holder.setText(R.id.dialog_event_menu2, SpannableUtil.build());

            SpannableUtil.append("症状描述：", BaseApp.getResource().getColor(R.color.color_bg_theme));
            SpannableUtil.append(model.getDescription(), BaseApp.getResource().getColor(R.color.color_black));
            holder.setText(R.id.dialog_event_menu3, SpannableUtil.build());
            SpannableUtil.append("事件时间：", BaseApp.getResource().getColor(R.color.color_bg_theme));
            SpannableUtil.append(model.getEvent_datetime(), BaseApp.getResource().getColor(R.color.color_black));
            holder.setText(R.id.dialog_event_menu4, SpannableUtil.build());
        }
    };

    public EventDialog(Activity activity) {
        super(activity);
    }

    @Override
    protected int initView() {
        return R.layout.layout_dialog_event;
    }

    @Override
    protected void initData() {
        findViewById(R.id.dialog_event_back).setOnClickListener(v -> dismiss());

        final RecyclerView recycler = findViewById(R.id.dialog_event_list);
        final CrashLinearLayoutManager manager = new CrashLinearLayoutManager(BaseApp.getContext());
        recycler.setLayoutManager(manager);
        recycler.setAdapter(adapter);
    }

    public void setList(List<InspectionBean.EventBean> list) {
        mDatas.clear();
        mDatas.addAll(list);
        adapter.notifyDataSetChanged();
    }

    public void setTitle(String str) {
        if (TextUtils.isEmpty(str)) return;
        final TextView time = findViewById(R.id.dialog_event_time);
        if (null == time) return;
        time.setText(str);
    }
}
